using System;
using Jalal.Library.DataStructure;
using System.Data;
using Jalal.Library.Data;
using BCGC.DAL;
using Jalal.Library.Utility;
namespace BCGC.BLL.Forum {
	
	public class PostCategoryListing {
		
		private int categoryID;
		public int CategoryID {
			get {
				return categoryID;
			}
		}

        private int postID;
        public int PostID
        {
            get
            {
                return postID;
            }
        }
				
		
		private String postTitle;
		public String PostTitle {
			get {
				return postTitle;
			}
		}
		
		private String postedBy;
		public String PostedBy {
			get {
				return postedBy;
			}
		}
		
		private DateTime postDate;
		public DateTime PostDate {
			get {
				return postDate;
			}
		}

        private int totalReply;
        public int TotalReply
        {
            get
            {
                return totalReply;
            }
        }

        internal PostCategoryListing(DataRow dataRow)
        {
            if (dataRow != null)
            {
                
                categoryID = (int)CommonUtility.FilterNull(dataRow["CategoryID"], typeof(int));
                postID = (int)CommonUtility.FilterNull(dataRow["PostID"], typeof(int));
                postTitle = (string)CommonUtility.FilterNull(dataRow["PostTitle"], typeof(string));
                postedBy = (string)CommonUtility.FilterNull(dataRow["UserName"], typeof(string));
                postDate = (DateTime)CommonUtility.FilterNull(dataRow["PostDate"], typeof(DateTime));
                totalReply = (int)CommonUtility.FilterNull(dataRow["TotalReply"], typeof(int));
            }
         }

        private static ReadWriteCustomCollection<PostCategoryListing> GetCollection(DataRowCollection rowCollection)
        {
            ReadWriteCustomCollection<PostCategoryListing> collection = new ReadWriteCustomCollection<PostCategoryListing>();

            foreach (DataRow dr in rowCollection)
            {
                collection.Add(new PostCategoryListing(dr));
            }
            return collection;
        }


        internal static ReadWriteCustomCollection<PostCategoryListing> GetAllRecentPosts(int categoryID,string sortBy,string sortDirection,int currentPage,int pageSize,out int totalCount)
        {
            DataFactory.GetDataMiner().BeginTransaction(true);
            DataTable result = PostData.GetPostListingByCategory(categoryID, sortBy, sortDirection, currentPage, pageSize,out totalCount);
            DataFactory.GetDataMiner().CommitTransaction();

            if (result.Rows.Count > 0)
                return GetCollection(result.Rows);
            else
                return null;
		}

	}

}
